package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo4 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            String sql= "SELECT s.name,s.age,s.gender,c.floor,c.name,t.name,t.age,t.salary "+
                    "FROM teacher t "+
                    "JOIN class c ON c.teacher_id = t.id "+
                    "JOIN student s ON s.class_id = c.id "+
                    "WHERE t.name='刘苍松'";
            ResultSet rs=statement.executeQuery(sql);
            while (rs.next()){
                String sname = rs.getString("s.name");
                int sage = rs.getInt("s.age");
                String sgender = rs.getString("s.gender");
                int cfloor = rs.getInt("c.floor");
                String cname = rs.getString("c.name");
                String tname = rs.getString("t.name");
                int tage = rs.getInt("t.age");
                int tsalary = rs.getInt("t.salary");
                System.out.println(sname+",\t"+sage+",\t"+sgender+",\t"+cfloor+",\t"
                                  +cname+",\t"+tname+",\t"+tage+",\t"+tsalary);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
